// 权限控制
import router from '@/router'
import store from '@/store'

// import NProgress from 'nprogress'
import 'nprogress/nprogress.css'

const whiteList = [
  '/login',
  '/404'
]

// 开启路由前置守卫
router.beforeEach((to, from, next) => {
  const token = store.state.user.token
  if (token) {
    if (token.path === '/login') {
      next('/')
    } else {
      next()
    }
  } else {
    if (whiteList.includes(to.path)) {
      next()
    } else {
      next('/login')
    }
  }
})
